﻿using System;
using System.IO;

class ReplaceOccurrences
{
    static void Main()
    {
        //Exercise 7.
        //Write a program that replaces all occurrences of the substring "start" with the substring "finish" in a text file. 
        //Ensure it will work with large files (e.g. 100 MB).

        StreamReader reader = new StreamReader(@"C:\Users\Toni\Desktop\Test Replace.txt");
        StreamWriter writer = new StreamWriter(@"C:\Users\Toni\Desktop\Test Replace Result.txt");

        try
        {
            string line = reader.ReadLine();
            while (line != null)
            {
                string replacedString = line.Replace("start", "finish");
                writer.WriteLine(replacedString);
                line = reader.ReadLine();
            }
        }
        finally
        {
            reader.Close();
            writer.Close();            
        }
    }
}

